package com.smart.thrift.base;

import java.util.Map;
import java.util.stream.Stream;

public interface Invocation {


    String getTargetServiceUniqueName();

    /**
     * get method name.
     *
     * @return method name.
     * @serial
     */
    String getMethodName();


    /**
     * get the interface name
     * @return
     */
    String getServiceName();

    /**
     * get parameter types.
     *
     * @return parameter types.
     * @serial
     */
    Class<?>[] getParameterTypes();

    /**
     * get parameter's signature, string representation of parameter types.
     *
     * @return parameter's signature
     */
    default String[] getCompatibleParamSignatures() {
        return Stream.of(getParameterTypes())
                .map(Class::getName)
                .toArray(String[]::new);
    }

    /**
     * get arguments.
     *
     * @return arguments.
     * @serial
     */
    Object[] getArguments();

    /**
     * get attachments.
     *
     * @return attachments.
     * @serial
     */
    Map<String, String> getAttachments();

    default void setAttachment(String key, String value) {
        getAttachments().put(key, value);
    };

    default void setAttachmentIfAbsent(String key, String value) {
        getAttachments().putIfAbsent(key, value);
    };

    /**
     * get attachment by key.
     *
     * @return attachment value.
     * @serial
     */
    default String getAttachment(String key) {
       return getAttachments().get(key);
    };

    /**
     * get attachment by key with default value.
     *
     * @return attachment value.
     * @serial
     */
    default String getAttachment(String key, String defaultValue) {
        return getAttachments().getOrDefault(key, defaultValue);
    };

}
